package com.project.psc.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Autowired
    CachingConnectionFactory connectionFactory;
    //创建rabbitmq模版
    @Bean
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }

    //创建队列 供应商注册
    @Bean
    public Queue supplierRegisterQueueOne() {
        return new Queue("supplierRegisterQueueOne");
    }

    //创建队列 发送投标书
    @Bean
    public Queue sendBiddTableQueueOne() {
        return new Queue("sendBiddTableQueueOne");
    }

    //创建队列 发送订单
    @Bean
    public Queue sendOrderQueueOne() {
        return new Queue("sendOrderQueueOne");
    }

    //创建队列 发送供货单
    @Bean
    public Queue sendSupplyQueueOne() {
        return new Queue("sendSupplyQueueOne");
    }


    //创建交换机
    @Bean
    public TopicExchange supplierOneExchange() {
        return new TopicExchange("supplierOne");
    }

    //交换机与队列绑定 供应商注册
    @Bean
    public Binding TopicExchangeToSupplierRegister(Queue supplierRegisterQueueOne, TopicExchange topicExchange) {
        return BindingBuilder.bind(supplierRegisterQueueOne).to(topicExchange).with("supplier.register");
    }

    //交换机与队列绑定 发送投标书
    @Bean
    public Binding TopicExchangeToSendBiddTable(Queue sendBiddTableQueueOne, TopicExchange topicExchange) {
        return BindingBuilder.bind(sendBiddTableQueueOne).to(topicExchange).with("supplier.sendBiddTable");
    }

    //交换机与队列绑定 发送订单
    @Bean
    public Binding TopicExchangeToSendOrderTable(Queue sendOrderQueueOne, TopicExchange topicExchange) {
        return BindingBuilder.bind(sendOrderQueueOne).to(topicExchange).with("supplier.sendOrder");
    }

    //交换机与队列绑定 发送投标书
    @Bean
    public Binding TopicExchangeToSendSupply(Queue sendSupplyQueueOne, TopicExchange topicExchange) {
        return BindingBuilder.bind(sendSupplyQueueOne).to(topicExchange).with("supplier.sendSupply");
    }
}
